package me.winds.test;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.View;

import com.zhy.autolayout.utils.AutoUtils;

import me.winds.wrapper.ViewHelper;
import me.winds.wrapper.WrapperDialog;


/**
 * Auther:  winds
 * Email:   heardown@163.com
 * Date:    2018/7/15.
 * Desc:
 */

public class CustomeDialog extends WrapperDialog {
    public CustomeDialog(Context context) {
        super(context);
    }

    @Override
    public int getLayoutRes() {
        return R.layout.dialog_custome;
    }

    @Override
    protected void setDialogParams(Dialog dialog) {
        setDialogParams(dialog, AutoUtils.getPercentWidthSize(984), AutoUtils.getPercentWidthSize(457), Gravity.CENTER);
    }

    @Override
    public void help(ViewHelper helper) {
        helper.setOnClickListener(R.id.tv_cancel, new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });
    }


    /**
     * 快捷设置参数
     *
     * @param listener 确认的监听事件
     * @param args     第一个为 标题  第二个为 内容  第三个为 确认  第四个为 取消
     */
    public WrapperDialog setUp(final OnConfirmListener listener, final String... args) {
        addHelperCallback(new HelperCallback() {
            @Override
            public void help(final Dialog dialog, ViewHelper helper) {
                if (args != null && args.length > 0) {
                    for (int i = 0; i < args.length; i++) {
                        switch (i) {
                            case 0:
                                helper.setText(R.id.tv_title, args[0]);
                                break;
                            case 1:
                                helper.setText(R.id.tv_content, args[1]);
                                break;
                            case 2:
                                helper.setText(R.id.tv_confirm, args[2]);
                                break;
                            case 3:
                                helper.setText(R.id.tv_cancel, args[3]);
                                break;
                        }
                    }
                }

                helper.setOnClickListener(R.id.tv_confirm, new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        listener.onConfirm(dialog, view);
                    }
                });
            }
        });
        return this;
    }

    public interface OnConfirmListener {
        void onConfirm(Dialog dialog, View view);
    }

}
